import React, { Component } from 'react'
import { connect } from 'react-redux'
import PropTypes from 'prop-types';

import { getUserList } from '../../redux/actions'

import UserList from '../../components/user-list/user-list'


export class Laoban extends Component {

  static propTypes = {
    user: PropTypes.object.isRequired,
    userList: PropTypes.array.isRequired,
    getUserList: PropTypes.func.isRequired
  }

  componentDidMount(){
    const { user, getUserList } = this.props
    const userListType = user.type === 'laoban' ? 'dashen' : 'laoban'
    getUserList(userListType)
  }
  
  render() {
    const { userList } = this.props
    return (
      <div>
        <UserList userList={userList} />
      </div>
    )
  }
}

export default connect(
  state => ({ user: state.user , userList: state.userList}),
  { getUserList }
)(Laoban)